let utils = {
    randomString(len) {
        len = len || 32;
        var chars = 'ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678'; /****默认去掉了容易混淆的字符oOLl,9gq,Vv,Uu,I1****/
        var maxPos = chars.length;
        var pwd = '';
        for (var i = 0; i < len; i++) {
            pwd += chars.charAt(Math.floor(Math.random() * maxPos));
        }
        return pwd;
    },
    setTimeout(timeout: number, cb?: (number) => void): Promise<number> {
        return new Promise(async resolve => {
            let timerID = setTimeout(() => {
                resolve(null)
            }, timeout);
            cb && cb(timerID)
        })
    },
    getRandomArrayNoRepeat(num: number, array): any[] {
        let arrayCopy = array.slice(0)
        let length = arrayCopy.length
        var k = []
        if (array.length < num) {
            num = array.length
        }
        for (var i = 0; i < num; i++) {
            var l = Math.floor(Math.random() * length)
            length = length - 1
            k.push(arrayCopy[l])
            arrayCopy[l] = arrayCopy[length]
        }
        return k
    },
    getOneFromArray(array: any[]): any {
        return array[Math.floor(Math.random() * array.length)]
    },

    getMapMax(mapProgressMax: number) {
        // let mapID = Math.floor(mapProgressMax / 100000000000) + 100000
        let _floor = Math.floor(mapProgressMax % 1000000000000 / 100000000)
        let c = _floor / 10 
        let f = _floor % 10
        if (c < 1) {
            c = 1
        } else {
            c = Math.floor(c) + (f == 0 ? 0 : 1)
        }
        if (f == 0 && _floor != 0) {
            f = 10
        } else if (_floor == 0) {
            f = 1
        }
        let mapID = 100000 + (c > 22 ? 22 : c)
        let floor = _floor > 210 ? _floor - 210 : f
        return { mapID, floor }
    }
   
}


export default utils